home *** CD-ROM | disk | FTP | other *** search
/ MacPeople 2001 February 15 / MACPEOPLE-2001-02-15.ISO.7z / MACPEOPLE-2001-02-15.ISO / オンラインウエア / 厳選オンラインウエア100 / マルチメディア / iView Multimedia 3.8.4ト.sea / iView Multimedia 3.8.4ƒ / AppleScript Support / Text file to Caption < prev    next >
Text File  |  2000-01-30  |  2KB  |  75 lines

  1. -- run the script
  2. main()
  3.  
  4.  
  5. -- ----------------------------------------------------------------------
  6. -- Sample script for importing a text file straght into the caption  
  7. -- of a field of a media object. This script goes thru' all items in a catalog
  8. -- opens associated text files (see function 'TextFileFromPath') and reads their
  9. -- text into the caption field.
  10. -- ----------------------------------------------------------------------
  11.  
  12. on main()
  13.     -- get the total number of items in the catalog
  14.     tell application "iView Multimedia"
  15.         set numObjects to the count objects of window 1
  16.     end tell
  17.     
  18.     -- for each item in the catalog
  19.     repeat with i from 1 to numObjects
  20.         
  21.         -- get the path of the item
  22.         tell application "iView Multimedia"
  23.             set thePath to the path of object i of window 1 as text
  24.         end tell
  25.         
  26.         -- form associated filename
  27.         set theTextFile to TextFileFromPath(thePath)
  28.         set theData to ""
  29.         
  30.         -- read text file (if it exists)
  31.         tell application "Finder"
  32.             if (exists file (theTextFile)) then
  33.                 set theData to read file theTextFile as text
  34.                 get theData
  35.             end if
  36.         end tell
  37.         
  38.         -- if we have some data, paste it in the caption field
  39.         if theData is not "" then
  40.             tell application "iView Multimedia"
  41.                 set the annotations of object i of window 1 to {caption:theData}
  42.             end tell
  43.         end if
  44.         
  45.     end repeat
  46.     
  47.     -- bring iView to the front
  48.     activate application "iView Multimedia"
  49. end main
  50.  
  51.  
  52. -- ----------------------------------------------------------------------
  53. -- In this script it is assumed that a text file is located at the same folder 
  54. -- as the associated image and its name is: 
  55. -- <image> name.i.jpg <text> name.txt.
  56. -- ----------------------------------------------------------------------
  57.  
  58. on TextFileFromPath(thePath)
  59.     set oldDelimiter to AppleScript's text item delimiters
  60.     
  61.     set AppleScript's text item delimiters to {":"}
  62.     set countPathItems to (the number of text items in thePath) - 1
  63.     set newPath to ""
  64.     repeat with i from 1 to countPathItems
  65.         set newPath to newPath & text item i of thePath & ":"
  66.     end repeat
  67.     
  68.     set theName to the last text item of thePath
  69.     set AppleScript's text item delimiters to {"."}
  70.     set newPath to newPath & text item 1 of theName & ".txt"
  71.     
  72.     set AppleScript's text item delimiters to oldDelimiter
  73.     
  74.     return newPath
  75. end TextFileFromPath